package com.hxkj.controller;

import com.hxkj.domain.po.Leaflet;
import com.hxkj.service.LeafletService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 单页控制层
 * <p>
 * created by zzx on 2018/6/6.
 */
@RestController
@RequestMapping("/leaflet")
public class LeafletController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LeafletController.class);

    @Autowired
    private LeafletService leafletService;


    /**
     * 获取单页列表
     *
     * @param parameterDataStruct 单页对象 和 分页信息
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Leaflet>> getLeafletList(@RequestBody ParameterDataStruct<Leaflet> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(leafletService.getLeafletList(parameterDataStruct.getData() == null ?
                new Leaflet() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }


    /**
     * 获取一条单页信息
     *
     * @param leaflet
     * @return 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Leaflet>> getLeaflet(@RequestBody Leaflet leaflet) throws Exception {
        return () -> leafletService.getLeaflet(leaflet);
    }

    /**
     * 新增单页
     *
     * @param Leaflet 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Leaflet>> saveLeaflet(@RequestBody Leaflet Leaflet) throws Exception {
        return () -> leafletService.saveLeaflet(Leaflet);
    }

    /**
     * 删除单页
     *
     * @param Leaflet 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> removerLeaflet(@RequestBody Leaflet Leaflet) throws Exception {
        return () -> leafletService.removerLeaflet(Leaflet);
    }


    /**
     * 修改单页
     *
     * @param Leaflet 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> updateLeaflet(@RequestBody Leaflet Leaflet) throws Exception {
        return () -> leafletService.updateLeaflet(Leaflet);
    }

    /**
     * 获取一条启用的单页信息
     *
     * @param leaflet
     * @return 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/getLeaflet", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<Leaflet>> getLeafletByStatus(@RequestBody Leaflet leaflet) throws Exception {
        return () -> leafletService.getLeafletByStatus(leaflet);
    }


    /**
     * 获取所有启用的单页信息
     *
     * @param leaflet
     * @return 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/getLeafletList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Leaflet>>> getLeafletList(@RequestBody Leaflet leaflet) throws Exception {
        return () -> leafletService.getLeafletList(leaflet);
    }

    /**
     * 根据自定义标签查询 对应的单页集合
     *
     * @param leaflet
     * @return 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/getLeafletByIds", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<List<Leaflet>>> getLeafletByIds(@RequestBody Leaflet leaflet) throws Exception {
        return () -> leafletService.getLeafletByIds(leaflet);
    }

    /**
     * 通过主键获取一条单页信息
     *
     * @param leaflet chenfangzhou
     * @return 单页信息
     * @throws Exception
     */
    @RequestMapping(value = "/getLeafletByPrimary", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<Leaflet> getLeafletByPrimary(@RequestBody Leaflet leaflet) throws Exception {
        return () -> leafletService.getLeafletByPrimary(leaflet);
    }

}






